<template>
  <div class="plat-form-wrap">
    <div class="body-wrap home-mini-width infoUser">
      <TitleCard
        title="专利导航预警报告"
        :showMore="false"
        :loading="loading"
        :isEmpty="isEmpty"
        :isSwitch="false"
        :type="'threeCard'"
      >
        <div v-if="total === 0" class="emptyData">
          <img src="../../assets/images/nodata.png" alt="" />
        </div>
        <MarketDemand
          v-else
          :tableList="tableList"
          @detailClick="detailClick"
          :total="total"
          @pageChange="pageChange"
          columnName="columnName"
          time="publishDate"
        ></MarketDemand>
        <Modal
          v-if="isShowModal"
          @cancel="cancel"
          @addSuccess="addSuccess"
          @cancelVisible="cancel"
        ></Modal>
      </TitleCard>
    </div>
  </div>
</template>

<script>
import Modal from './components/modal.vue'
import MarketDemand from '@/components/common/MarketDemand'
import { mapGetters, mapMutations } from 'vuex'
import mixinsBackStack from '@/views/backstageSupport/mixins'
import { getNavBrandList, getApplyNav, downNum } from '@/api/dataNavigation'
import FrontMixins from '@/mixins/frontMixin'

export default {
  mixins: [mixinsBackStack,FrontMixins],
  data() {
    return {
      params: {
        pageSize: 10,
        pageNum: 1,
      },
      loading: false,
      isEmpty: false,
      isShowModal: false, //当前历史用户未填写过表单的则弹出表单给填写
      total: 0,
      tableList: [],
      isApply: ''
    }
  },
  components: {
    MarketDemand,
    Modal
  },
  computed: {
    ...mapGetters('user', ['visitor']),
  },
  mounted() {
    this.getIsAplly()
    this.initSetting()
  },
  methods: {
    ...mapMutations('headerMenu', ['updateMenuItemStatus']),
    async getIsAplly() {
      const { data } = await getApplyNav()  //此处后端已做限制，如果没有登录则没有权限
      this.isApply = data
    },
    addSuccess() {
      this.isShowModal = false
    },
    cancel() {
      this.isShowModal = false
    },
    async detailClick(item) {
      if (this.authorityManagement()) {
        return
      }
      if (this.isApply !== 0) {
        this.isShowModal = true
      } else {
        await downNum()  //记录下载量
        const a = document.createElement('a')
        a.href = item.file.filePath
        a.download = item.file.fileName
        a.click()
      }
    },
    async initSetting() {
      const { rows, total } = await getNavBrandList({ ...this.params, category: 1 })
      this.tableList = rows
      this.total = total
    },
    pageChange(e) {
      this.params.pageNum = e
      this.initSetting()
    },
  }
}
</script>
